package cn.digitalize.system.modular.auth.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.digitalize.system.core.util.StpLoginUserUtil;
import cn.digitalize.system.modular.auth.param.AuthLoginParam;
import cn.digitalize.system.modular.auth.result.BaseLoginUser;
import cn.digitalize.system.modular.auth.service.AuthService;
import org.springframework.stereotype.Service;

/**
 * @author Created by ZhangCheng on 2023/06/05 (登录授权)
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Override
    public String doLogin(AuthLoginParam authLoginParam) {
        BaseLoginUser baseLoginUser = new BaseLoginUser();
        baseLoginUser.setAccount("test");
        // 执行登录
        StpUtil.login("12345678");
        //缓存用户信息
        StpLoginUserUtil.setLoginUser(baseLoginUser);
        System.out.println("======");
        return StpUtil.getTokenInfo().tokenValue;
    }

    @Override
    public BaseLoginUser getLoginUser() {
        BaseLoginUser baseLoginUser = StpLoginUserUtil.getLoginUser();
        return baseLoginUser;
    }
}
